package logic

import (
	"bw-renting/order-rpc/orderclient"
	"context"

	"bw-renting/api/internal/svc"
	"bw-renting/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PayOrderLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPayOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PayOrderLogic {
	return &PayOrderLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// TODO: 订单支付(支付宝支付)
func (l *PayOrderLogic) PayOrder(req *types.PayOrderReq) (resp *types.Data, err error) {
	// todo: add your logic here and delete this line
	OrderId := req.OrderId
	//调用支付服务
	pay, err := l.svcCtx.OrderServer.OrderPay(l.ctx, &orderclient.OrderPayReq{
		OrderId: int64(OrderId),
	})
	if err != nil {
		return &types.Data{
			Code:    -1,
			Message: "支付失败",
		}, err
	}
	//返回用户支付地址
	return &types.Data{Code: 200, Message: "success", Data: map[string]string{"pay_url": pay.PayUrl}}, nil

}
